 # -*- coding: utf-8 -*-

from datetime import datetime
import sc_engine.scrape.service as service

import unittest

class TestFunctionalService(unittest.TestCase):
    def test_get_proleague_matches(self):
        date = datetime(2009, 6, 3)
        league = u'신한은행 프로리그 08-09시즌'

        results = service.get_proleague_matches(date)

        self.assertEquals(results['league'], league)
        self.assertEquals(results['date_played'], date)
        self.assertEquals(len(results['matches']), 2)

        m1, m2 = results['matches']

        self.assertEquals(m1['team_one'], u'KT')
        self.assertEquals(m1['team_two'], u'MBC게임')

        self.assertEquals(m1['winner'], u'KTF')
        self.assertEquals(m1['winner_score'], 3)
        self.assertEquals(m1['loser_score'], 1)

        self.assertEquals(m1['games'][0]['map'], 1193)

        self.assertEquals(m1['games'][0]['player_one'], 988)
        self.assertEquals(m1['games'][0]['player_two'], 851)

        self.assertEquals(m1['games'][4]['map'], 1207)
        self.assertEquals(m1['games'][4]['player_one'], None)
        self.assertEquals(m1['games'][4]['player_two'], None)

    def test_get_no_proleague_matches(self):
        date = datetime(2009,6,4)

        result = service.get_proleague_matches(date)

        self.assertEquals(result, None)


    def test_get_map(self):
        map_id = 1193

        map = service.get_map_info(map_id)

        self.assertEquals(map['name'], 'Destination')
        self.assertEquals(map['version'], '1.1')

    def test_get_player(self):
        player_id = 988

        player = service.get_player_info(player_id)

        self.assertEquals(player['name'], 'Never_V_')
        self.assertEquals(player['race'], 'terran')
